<?php
class Application_Model_Operate extends Application_Model_DomainObject{

    protected $_id; 
    protected $_operate_name; 
    protected $_money; 
    protected $_type;
    protected $_createdate;
    protected $_reid; 
    protected $_content; 
    protected $_userid; 
    protected $_ip; 
   
    public static function addOperate($money,$type,$reid,$content,$userId) {
        $ip = Application_Model_Operate::get_local_ip();
        $operateItem = new Application_Model_Operate();
        $operateItem->operate_name = Uuch_Util::getUserNikeName();
        $operateItem->money = $money;
        $operateItem->type = $type;
        $operateItem->createdate = date("Y-m-d H:i:s");
        $operateItem->reid = $reid;
        $operateItem->ip = $ip;
        $operateItem->userid = $userId;
        $operateItem->content = $content;
        $operateItem->save();
        return true;
    }
    
    public static function getserFilter($quick,$dateinbegin,$dateinend,$pagesize, $pageindex)
    {
        $where = array();
        $and = "";
        if($quick != ""){
            $and = " ( ";
            $where[$and." operate_name like "] = "%".$quick."%";
            $and = " or ";
            $where[$and." reid like "] = "%".$quick."%";
            $where[$and." content like "] = "%".$quick."%";
            $where[$and." userid like "] = "%".$quick."%";
            $uwhere[" storeno like "] = "%".$quick."%";
            $userItem = Application_Model_User::getDao()->queryAll($uwhere);
            if($userItem){
                $userid = "(";
                foreach ($userItem as $uvalue) {
                    $userid .= $uvalue->id.",";
                }
                $userid .= "0)";
                $where[$and." userid in "] = $userid;
            }
            $where[" ) and 1 = "] = 1;
            $and = " and ";
        }
        if($dateinbegin != ""){
            $where[$and." createdate >= "] =$dateinbegin;
            $and = " and ";
        }
        if($dateinend != ""){
            $where[$and." createdate <= "] =$dateinend;
            $and = " and ";
        }
        return Application_Model_Operate::getDao()->queryPage($where, " createdate desc ", $pagesize, $pageindex);
    }
    
    public function getuserde()
    {
        if($this->userid){
            return Application_Model_User::load($this->_userid);
        }
    }
    public static function get_local_ip()
    {
//        $arr = "";
//        exec("ipconfig /all",$arr); //运行这句需要修改php.ini文件并重启apache
//	if (is_array($arr)){
//            foreach ($arr AS $val) {
//                if (preg_match("/IPv4/", $val)) {
//                    $pip = substr($val, strpos($val, ":") + 1);
//                    if (preg_match("/192\.168\.1\./", $pip)) {  
//                        $pip = explode("(",$pip);
//                        return $pip[0];
//                    }
//                    if (preg_match("/192\.168\.2\./", $pip)) {  
//                        $pip = explode("(",$pip);
//                        return $pip[0];
//                    }
//                    if (preg_match("/192\.168\.3\./", $pip)) {  
//                        $pip = explode("(",$pip);
//                        return $pip[0];
//                    }
//                }
//            }
//	}
        if(!empty($_SERVER["HTTP_CLIENT_IP"])){
            $cip = $_SERVER["HTTP_CLIENT_IP"];
        }
        elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        }
        elseif(!empty($_SERVER["REMOTE_ADDR"])){
            $cip = $_SERVER["REMOTE_ADDR"];
        }
        else{
            $cip = "无法获取！";
        }
        return $cip;
    }
    
    public static function getWayIdTypeByOperate($wayId,$type)
    {
        $where[" reid = "] = $wayId;
        $where[" and userid = "] = $type;
        return self::getDao()->queryAll($where," createdate desc");
    }
    
    
}

  